package com.jack.thinking.java._22.swing.button;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.utils.SwingConsole;

public class RadioButtons extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JTextField t = new JTextField(15);
	private ButtonGroup g = new ButtonGroup();
	private JRadioButton rb1 = new JRadioButton("1", true);
	private JRadioButton rb2 = new JRadioButton("2", true);
	private JRadioButton rb3 = new JRadioButton("3", true);
	
	private ActionListener al = new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			t.setText("Radio button " + ((JRadioButton)e.getSource()).getText()); 
		}
	};
	
	public RadioButtons() {
		rb1.addActionListener(al);
		rb2.addActionListener(al);
		rb3.addActionListener(al);
		g.add(rb1); g.add(rb2); g.add(rb3);
		t.setEditable(false);
		setLayout(new FlowLayout());
		add(t);
		add(rb1);
		add(rb2);
		add(rb3);
	}
	
	public static void main(String[] args) {
		SwingConsole.run(new RadioButtons(), 200, 125);
	}
}
